1. Field of the Invention
The present invention relates to a method, system, and program for implementing a locking mechanism for a shared resource.
2. Description of the Related Art
Almost all computer architectures provide a locking mechanism to control the execution of concurrent operations directed to a shared resource in a manner that ensures that no two processes execute their critical sections concurrently. This means that two processes cannot be allowed to simultaneously proceed with mutually exclusive atomic operations. In prior art systems, a process, such as a write operation, that requires exclusive access to a shared resource must obtain an exclusive lock on the shared resource that prevents any other process from concurrently accessing the resource. A process requiring non-exclusive access, such as a read operation, must obtain a nonexclusive lock to access the resource. Multiple resources with a non-exclusive lock may concurrently access the resource associated with the lock.
Computer operating systems implement some form of a locking mechanism to control how processes are allowed access to resources. Application programs also implement a locking mechanism to control access to shared application resources, such as database tables, files, etc. For instance, database programs institute locking to prevent two different requests from performing mutually exclusive operations with respect to database records.
Notwithstanding the widespread use of locking, software developers writing programs in computer languages intended to execute across multiple operating systems through the use of a virtual machine layer, such as the Java programming language, have faced difficulties implementing locking mechanisms. One prior art solution is to write separate native locking mechanisms for each operating system on which the cross-platform application will execute. When the application requires locking, the application would call the native locking mechanisms written for the specific operating system. This approach is especially cumbersome because the software developer must write separate native locking mechanisms for each operating system on which the application is designed to run. For this reason, many Java applications do not implement a locking mechanism.
Moreover, even if a locking mechanism is implemented in Java that utilizes the native operating system locking mechanisms, in cases where the Java application partially fails, the lock may remain in place in the operating system tables even though the Java process is no longer functional. Such a result of a partial crash can be quite common in applications that use a virtual machine or extra translation level, such as the Java Virtual Machine, between the executing application and operating system.
For these reasons, there is a need in the art to provide a technique for implementing a locking mechanism for applications implemented in computer languages that are intended to execute across multiple operating system platforms.